/**
 * @see https://umijs.org/docs/max/access#access
 * */
export default function access(initialState: { currentUser?: SYSTEM.User } | undefined) {
  const { currentUser } = initialState ?? {};
  if (currentUser?.roles && currentUser.roles.length > 0) {
    currentUser.roles.forEach((role) => {
      if (role.name === 'admin') {
        return {
          canAdmin: true,
        };
      }
    });
  }
  return {
    canAdmin: false,
  };
}
